import { defineStore } from "pinia";

export const useConfigureStore = defineStore("configure", {
  state: () => ({
    token: false, // 用户是否登录
    showAside: false, // 是否显示侧边栏
    searchWord: "", // 搜索关键词
    activeNavName: "", // 导航栏名称
  }),
  getters: {
    getToken: (state) => state.token,
    getActiveNavName: (state) => state.activeNavName,
    getShowAside: (state) => state.showAside,
    getSearchWord: (state) => state.searchWord,
  },
  actions: {
    setToken(token: boolean) {
      this.token = token;
    },
    setActiveNavName(name: string) {
      this.activeNavName = name;
    },
    setShowAside(show: boolean) {
      this.showAside = show;
    },
    setSearchWord(word: string) {
      this.searchWord = word;
    },
  },
  persist: {
    storage: localStorage, // 也可以使用 sessionStorage
    pick: ["token"], // 指定需要持久化的数据
  },
});
